<template>
	<view>
		<!-- 导航栏 -->
		<view class="flex justify-between align-center mainBgColor pos-f" style="height: 44px; left: 0; right: 0; top: 0; z-index: 9;">
			<view class="flex align-center" style="padding: 0 8px;">
				<u-icon name="arrow-left" size="21" color="#ffffff" @click="toBack()"></u-icon>
			</view>
			
			<view class="font-16 color-white font-b-800">
				<text>维修历史</text>
			</view>
			
			<view class="flex align-center mar-r-10" @click="handleSearch()">
				<text class="iconfont icon-sousuo color-white" style="font-size: 20px;"></text>
			</view>
		</view>
		
		<view v-if="!loading && list.length > 0" style="padding-top: 44px;">
			<List
				class="mar-b-10"
				v-for="(item, index) in list"
				:key="index"
				:id="item.RepairTaskId"
				:state="state"
				:orderNo="item.RepairTaskNum"
				:dates="item.CreateDate"
				:customerName="item.Customer.CName"
				:currentRow="item"
				@handleItemClick="handleItemClick"
			/>
		</view>
		
		<view v-if="list.length > 0" class="flex justify-center mar-t-40 pad-b-20 color-999999">
			<text>~ 没有更多数据了</text>
		</view>
		
		<!-- 页面加载 -->
		<u-loading-page :loading="loading" loadingText="加载中..." fontSize="16px"></u-loading-page>
		
		<!-- 空数据 -->
		<u-empty
			v-if="list.length === 0 && !loading" mode="data"
			text="~暂无数据"
			icon="http://cdn.uviewui.com/uview/empty/data.png"
			style="padding-top: 44px;"
		></u-empty>
	</view>
</template>

<script>
	import List from '@/components/Repair/List/index'
	
	import { mapState } from 'vuex'
	import { checkLogin, getSystemDate } from '@/utils/lib'
	import { getRepairHistory } from '@/apis/repairManage'
	
	export default {
		components: {
			List,
		},
		
		computed: {
			...mapState({
				token: state => state.user.token,
				longitude: state => state.user.longitude,
				latitude: state => state.user.latitude,
			})
		},
		
		data() {
			return {
				state: 0, // 此页面没有状态，但是为了使用通用组件，状态默认 0
				cartNum: null, // 车号
				loading: false, // 加载
				list: [], // 列表数据
				total: 0, // 列表数据
			}
		},
		
		onLoad(options) {
			// 获取车号
			this.cartNum = options.cartNum
		},
		
		onShow() {
			checkLogin()
			this.findList()
		},
		
		methods: {
			// 返回上一页
			toBack() {
				uni.navigateBack({ delta: 1 })
			},
			
			// 查询列表
			findList() {
				let params = {
					VehicleNumber: this.cartNum,
					token: this.token,
					location: this.longitude + ',' + this.latitude
				}
				
				this.loading = true
				
				getRepairHistory(params).then(res => {
					this.loading = false
					this.list = res.Result
					this.total = this.list.length
				}).catch(err => {
					this.loading = false
				})
			},
			
			// 点击搜索按钮的回调
			handleSearch() {},
			
			// 跳转到详情页
			handleItemClick(id) {
				uni.navigateTo({
					url: `/pages/repairManage/repairHistory/details?&orderNo=${ id }`
				})
			},
		}
	}
</script>

<style>

</style>
